package br.ufpe.cin.imlm2.jbeat.paths;

import java.util.ArrayList;
import java.util.List;

import br.ufpe.cin.imlm2.jbeat.model.LightWeightClass;
import br.ufpe.cin.imlm2.jbeat.model.LightWeightMethod;

public class ExceptionChain extends SimpleExceptionPath {

	private List<Integer> rethrowIndices;
	
	public ExceptionChain(LightWeightClass exception) {
		super(exception);
		this.rethrowIndices = new ArrayList<Integer>();
	}
	
	/**
	 * Adds this method to the path and marks it as a rethrow node.
	 * @param m
	 */
	public void addRethrowPoint(LightWeightMethod m){
		this.addPoint(m);
		this.rethrowIndices.add(this.getNodes().size() - 1);
	}
	/**
	 * Tells if the n-th node in this path (chain) is a rethrow node.
	 * If n < 0 or n >= lenth() this method will return false.
	 * @param n
	 * @return true if the n-th node is a rethrow node.
	 */
	public boolean isRethrowNode(int n){
		if(n < 0 || n >= this.length())
			return false;
		return this.rethrowIndices.contains(n);
	}
	

}
